package cn.shangqizhenshuai.sqiot.action;

import cn.shangqizhenshuai.sqiot.Filter.UserLoginMap;
import cn.shangqizhenshuai.sqiot.Serivce.EquipmentService;
import cn.shangqizhenshuai.sqiot.Serivce.UserService;
import com.google.gson.Gson;
import com.sun.org.apache.xerces.internal.impl.dv.util.HexBin;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("user")
public class UserAction {
    @Autowired
    private UserService userService;
    @Autowired
    UserLoginMap userLoginMap;
    @ResponseBody
    @RequestMapping("/login")
    public Map login(String username,String password,HttpSession session) throws NoSuchAlgorithmException {
        HashMap<String, String> stringStringHashMap = new HashMap<>();
        if(userService.login(username,password)){

        }else{
            //密码错误
            //00001密码错误
            stringStringHashMap.put("errorcode","00001");
        }
        return stringStringHashMap;
    }

    @ResponseBody
    @RequestMapping("/add")
    public Map add(String username,String password){
        boolean adduser = userService.adduser(username, password);
        HashMap<String, Object> stringStringHashMap = new HashMap<>();
        stringStringHashMap.put("data",adduser);
        stringStringHashMap.put("errorcode","00001");
        return stringStringHashMap;
    }
}
